home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.02 Feb 96 / 12.02 Getting Started / CSingleCharPane.cp < prev    next >
Encoding:
Text File  |  1995-11-21  |  1.5 KB  |  81 lines  |  [TEXT/CWIE]

  1. #include <LPane.h>
  2. #include <LCommander.h>
  3. #include "CSingleCharPane.h"
  4.  
  5. CSingleCharPane *
  6. CSingleCharPane::CreateSingleCharPaneStream( LStream *inStream )
  7. {
  8.     return( new CSingleCharPane( inStream ) );
  9. }
  10.  
  11.  
  12. CSingleCharPane::CSingleCharPane( LStream *inStream ) : LPane( inStream )
  13. {
  14.     mChar = 'x';
  15. }
  16.                         
  17.  
  18. Boolean        
  19. CSingleCharPane::HandleKeyPress( const EventRecord &inKeyEvent )
  20. {
  21.     mChar = inKeyEvent.message & charCodeMask;
  22.     
  23.     SetUpdateCommandStatus( true );
  24.     Refresh();
  25.     
  26.     return true;
  27. }
  28.  
  29.  
  30. Boolean
  31. CSingleCharPane::ObeyCommand( CommandT inCommand,
  32.                                     void *ioParam )
  33. {
  34.     if ( inCommand == 1000 )
  35.     {
  36.         SysBeep( 20 );
  37.         return true;
  38.     }
  39.     else
  40.         return LCommander::ObeyCommand(inCommand, ioParam);
  41. }
  42.  
  43.  
  44. void
  45. CSingleCharPane::FindCommandStatus( CommandT inCommand,
  46.                                     Boolean &outEnabled,
  47.                                     Boolean &outUsesMark,
  48.                                     Char16 &outMark,
  49.                                     Str255 outName )
  50. {
  51.     if (inCommand == 1000)
  52.         outEnabled = (mChar == 'x');
  53.     else
  54.         LCommander::FindCommandStatus(inCommand, outEnabled,
  55.                                     outUsesMark, outMark, outName);
  56. }
  57.  
  58.  
  59. void
  60. CSingleCharPane::DrawSelf()
  61. {
  62.     Rect        frameRect;
  63.     short        x, y, frameWidth, frameHeight;
  64.     const short kFontSize = 128;
  65.     FontInfo    myFontInfo;
  66.     
  67.     CalcLocalFrameRect( frameRect );
  68.     
  69.     frameWidth = frameRect.right - frameRect.left;
  70.     frameHeight = frameRect.bottom - frameRect.top;
  71.     
  72.     TextSize( kFontSize );
  73.     
  74.     x = (frameWidth - CharWidth( mChar )) / 2 + frameRect.left;
  75.     
  76.     GetFontInfo( &myFontInfo );
  77.     y = frameRect.bottom - ((frameHeight - myFontInfo.ascent + myFontInfo.descent) / 2);
  78.     
  79.     MoveTo( x, y );
  80.     DrawChar( mChar );
  81. }